package com.lanyam.travel.base.controller;


import com.lanyam.travel.base.utils.JSONResult;
import com.lanyam.travel.base.entity.GoodsInfo;
import com.lanyam.travel.base.entity.OrderReject;
import com.lanyam.travel.base.entity.TravelOrder;
import com.lanyam.travel.base.entity.vo.GoodsInfoVo;
import com.lanyam.travel.base.service.IGoodsInfoService;
import com.lanyam.travel.base.service.IOrderRejectService;
import com.lanyam.travel.base.service.ITravelOrderService;
import com.lanyam.travel.base.utils.JsonMapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;


@RestController
@RequestMapping("/reject")
public class OrderRejectController {

	@Autowired
	private ITravelOrderService travelOrderService;
	
	@Autowired
	private IOrderRejectService orderRejectService;
	
	/**
	 * 驳回订单
	 * @param orderId
	 * @param confirmUserId 订单二审用户id
	 * @param reason
	 * @return
	 */
	@PostMapping("/rejectOrder")
	public JSONResult rejectOrder(String orderId,String confirmUserId,String reason)
	{
		if(StringUtils.isEmpty(orderId) || StringUtils.isEmpty(confirmUserId))
		{
			return JSONResult.errorMsg("参数不全");
		}
		TravelOrder order = travelOrderService.queryOrderById(orderId);
		order.setVerifyStatus(3);
		order.setConfirmTime(new Date());
		order.setConfirmUserId(confirmUserId);
		travelOrderService.updateOrder(order);
		
		String id = UUID.randomUUID().toString().replace("-", "");
		OrderReject reject = new OrderReject();
		reject.setId(id);
		reject.setOrderId(orderId);
		reject.setReason(reason);
		reject.setRejectTime(new Date());
		reject.setRejectUserId(confirmUserId);
		orderRejectService.insert(reject);
		return JSONResult.ok(reject);
	}
	
	/**
	 * 获取订单驳回记录
	 * @param orderId
	 * @return
	 */
	@PostMapping("/getOrderRejectRecord")
	public JSONResult getOrderRejectRecord(String orderId)
	{
		if(StringUtils.isEmpty(orderId))
		{
			return JSONResult.errorMsg("参数不全");
		}
		List<OrderReject> recordList = orderRejectService.getOrderRejectRecord(orderId);
		return JSONResult.ok(recordList);
	}
}